<template>
	<view class="content">
		<view class="header">
			<view class="denglu">立即注册</view>
			<input type="text" placeholder="请输入手机号码" class="zh" v-model="mobile">
			<view class="header_a flexbetween">
				<input type="text" placeholder="请输入手机验证码" class="mm" v-model="code">
				<view class="huoqu" @click="sendcode">{{codetext}}</view>
			</view>
			<view class="header_a flexbetween">
				<input type="text" placeholder="请输入密码" class="mm"  v-model="passwordtext">
				<!-- <image src="../../static/eyes.png" mode="" class="yan"></image> -->
			</view>
			<view class="header_a flexbetween">
				<input type="text" placeholder="请再次输入密码" class="mm"  v-model="password">
				<!-- <image src="../../static/eyes.png" mode="" class="yan"></image> -->
			</view>
			<view class="flexright margin_top">
				<view class="xiaohui">已有账户, <text class="xiaohuang" @click="denglu"> 立即登录</text></view>
			</view>
			<view class="dl" @click="regist">注册</view>
			
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				quan: false,
				mobile: "",
				passwordtext: "",
				password: "",
				code: "",
				codetext: "获取验证码",
			}
		},
		methods: {
			// 发送验证码
			sendcode() {
				let _this = this
				let mobile = _this.mobile;
				if (!mobile.match(/^1\d{10}$/)) {
					httpRequest.toast("请输入有效的手机号码");
					return false;
				}
				httpRequest.request('sms/send', 'POST', {
					mobile: mobile,
					event: "register"
				}).then(resp => {
					if (resp.code == 1) {
						var i = 60;
						var timer = setInterval(function() {
							_this.codetext = i + "秒";
							if (i < 1) {
								clearInterval(timer);
								_this.codetext = "获取验证码";
							} else {
								i--;
							}
						}, 1000)
			
					} else if (resp.code == 0) {
						httpRequest.toast(resp.msg);
					} else {
						httpRequest.toast('网络开小差啦');
					}
				})
			},
			// 注册
			regist() {
				let _this = this
				let mobile = _this.mobile;
				
				if (mobile == '') {
					httpRequest.toast('请输入手机号');
					return false;
				}
				if (!mobile.match(/^1\d{10}$/)) {
					httpRequest.toast("请输入有效的手机号码");
					return false;
				}
				if (_this.code == '') {
					httpRequest.toast("请输入验证码");
					return false;
				}
				if (_this.passwordtext == '') {
					httpRequest.toast("请输入密码");
					return false;
				}
				if (_this.password == '') {
					httpRequest.toast("请输入确认密码");
					return false;
				}
				if (_this.passwordtext != _this.password) {
					httpRequest.toast("两次输入密码不一致,请重新输入")
					return false
				}
				httpRequest.request('/user/register', 'GET', {
					mobile: _this.mobile,
					password: _this.password,
					code: _this.code,
				}).then(res => {
					httpRequest.toast(res.msg);
					if (res.code == 1) {
						setTimeout(function() {
							uni.navigateBack({
								delta: 1
							});
						}, 500)
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			denglu() {
				uni.navigateBack({
					delta: 1
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #ffffff;
		// min-height: 80vh;
	}

	.yan {
		width: 22rpx;
		height: 16rpx;
		background-size: 100% 100%;
		margin-right: 14rpx;
	}

	.header {
		padding: 0rpx 30rpx;
	}

	.denglu {
		padding-top: 208rpx;
		font-size: 40rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	input:input-placeholder {
		color: #999999;
	}

	.zh {
		margin-top: 86rpx;
		padding-bottom: 28rpx;
		border-bottom: 1rpx solid rgba(153, 153, 153, 0.10);
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
	}
	.dui1{
			 width: 23rpx;
			 height: 23rpx;
			 margin-right:7rpx;
				 border: 1rpx solid #999;
				 border-radius: 50%;
	}

	.mm {
		margin-top: 44rpx;
		padding-bottom: 28rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
	}

	.header_a {
		border-bottom: 1rpx solid rgba(153, 153, 153, 0.10);
	}

	.huoqu {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #fe7200;
		margin-right: 14rpx;
		min-width: 200rpx;
		text-align: right;
	}

	.wangji {
		margin-top: 28rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.yue {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
		margin-top: 71rpx;
		margin-left: 10rpx;
		margin-right: 8rpx;
	}

	.dui {
		width: 24rpx;
		height: 24rpx;
		margin-right: 7rpx;
	}

	.dl {
		margin-left: 10rpx;
		margin-right: 8rpx;
		height: 82rpx;
		margin-top: 29rpx;
		background-color: #fe7200;
		font-size: 32rpx;
		border-radius: 41rpx 41rpx 41rpx 41rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		line-height: 82rpx;
		text-align: center;
	}

	.my {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
		text-align: center;
		margin-top: 29rpx;
	}

	.lj {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #fe7200;
		text-align: center;
		margin-top: 29rpx;
	}
</style>
